package cn.auto.controller;

import com.jfinal.core.ActionKey;

import cn.auto.service.UserService;
import cn.auto.utility.HelperController;
import cn.auto.utility.ResponseInfo;
import cn.auto.utility.Status;
import net.sf.json.JSONObject;

public class LoginController extends HelperController {
	
	UserService service=new UserService();
	
	public void index() {
		render("login.html");
	}
	
	@ActionKey("/login")
	public void login() {		
		JSONObject jo1 = readRequstJson();
		String un=jo1.getString("uname");
		String psw=jo1.getString("psw");
		String st = service.login(un, psw);

		if (st.equals(Status.SUCCESS)) {
			renderJson(ResponseInfo.create(st, "登录成功！",service.getUserInfo(un)));
		}else {
			renderJson(ResponseInfo.create(st, "登录失败！"));
		}
	}
	
}
